const nums1 =
[7,5,6]
// [6,4,3,7,2,1,8,5]
const nums2 = 
[1,4]
// [6,8,5,3,1,7,4,2]

var minNumber = function(nums1, nums2) {
    var arr =[]
    for (const m of nums1) {
        arr.push(nums2.find(el =>m=== el))
        arr.sort((a,b)=> a-b)
    }
    console.log();
    if(!arr[0]){
        nums1.sort((a,b)=> a-b)
        nums2.sort((a,b)=> a-b)
        return nums1[0] > nums2[0] ? nums2[0]*10 + nums1[0] : nums1[0]*10 + nums2[0]
    }

    return arr[0]
};

console.log(minNumber(nums1,nums2));
